//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System;
using System.Collections.Generic;

namespace GuidanceExplorer.Model
{
    public class GuidanceItemFileReferenceCollection : Dictionary<string, GuidanceItemFileReference>, IGuidanceItemContainer
    {
        /// <summary>
        /// Factory.
        /// </summary>
        /// <returns>A new instance of the GuidanceItemCollection</returns>
        public static GuidanceItemFileReferenceCollection New()
        {
            return new GuidanceItemFileReferenceCollection();
        }

        /// <summary>
        /// The columns for this collection.
        /// </summary>
        private ColumnCollection _columns;

        /// <summary>
        /// Default private constructor.
        /// </summary>
        private GuidanceItemFileReferenceCollection() { }

        public override bool Equals(object obj)
        {
            GuidanceItemFileReferenceCollection other = obj as GuidanceItemFileReferenceCollection;
            if (other != null)
            {
                if (this.Count != other.Count) return false;
                IEnumerator<GuidanceItemFileReference> _thisCollection = this.Values.GetEnumerator();
                IEnumerator<GuidanceItemFileReference> _otherCollection = other.Values.GetEnumerator();
                while (_thisCollection.MoveNext() && _otherCollection.MoveNext())
                {
                    if (!_thisCollection.Current.Equals(_otherCollection.Current))
                    {
                        return false;
                    }
                }
                return true;
            }
            else
            {
                return base.Equals(obj);
            }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #region IGuidanceItemContainer Members

        /// <summary>
        /// Return the columns for the guidance view.
        /// </summary>
        public ColumnCollection Columns
        {
            get
            {
                if (_columns == null)
                {
                    _columns = ColumnCollection.DefaultColumns(GuidanceType.New(GuidanceType.DefaultTypeName));
                }
                return _columns;
            }
            set
            {
                _columns = value;
            }
        }

        public GuidanceItemCollection Items
        {
            get { throw new Exception("The method or operation is not implemented."); }
            set { throw new Exception("The method or operation is not implemented."); }
        }

        public bool HasItems
        {
            get { return false; }
        }

        public bool CanSetItems
        {
            get { return false; }
        }

        #endregion

        #region IEnumerable<GuidanceItem> Members

        public new IEnumerator<GuidanceItem> GetEnumerator()
        {
            foreach (GuidanceItemFileReference gifr in this.Values)
            {
                yield return gifr;
            }
        }

        #endregion

    }
}

